var sysParam = {};
var sysParam = function () {
    //本身
    var $this = this;
    this.init = function () {
        //实例化表格
        layuiFunciton.tableInit({
            tableId: 'modelTableId',
            url: '/ngu/sys/findSysList',
            id: 'modelId',
            searchFromId: 'searchFrom',
            tableFilter: 'modelList', //表格监听名称,
            page: true,
            cols: [
                [  {
                    field: 'account',
                    title: '账号名称',
                    align: "rigth"
                },
                {
                field: 'name',
                title: '真实姓名',
                align: "rigth",
                sort: true
                },
                {
                field: 'enabled',
                title: '是否启用',
                align: "rigth",
                sort: true,
                    templet:function (d) {
                    if(d.enabled == 0){
                        return "<span style='color: #b2b2b2'> <input type='checkbox'    value='"+d.id+"、"+d.enabled+"' lay-skin='switch' lay-filter='switchTest' lay-text='启用|禁用'></span>";
                    }else{
                        return "<span style='color: #b2b2b2'> <input type='checkbox' checked   value='"+d.id+"、"+d.enabled+"' lay-skin='switch'  lay-filter='switchTest' lay-text='启用|禁用'></span>";
                    }

                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: "rigth",
                    sort: true
                },{
                    field: 'lastLoginTime',
                    title: '最后登录时间',
                    align: "rigth",
                    sort: true
                },
                {
                title: '操作',
                align: "center",
                width: 150,
                templet: '#modelBar',
                fixed: 'right'
                }

                ]
            ],

            tools: {
                edit: {
                    returnData: function (rowData) {
                        var wid = Math.floor($(window).width() / 7.5 * 5) + "px";
                        var hei = Math.floor($(window).height() / 7.5 * 6) + "px";
                        layuiFunciton.layerOpen({
                            title: "修改人员信息",
                            finder: '#editForm',
                            content: "/ngu/pages/sys/user/edit.html",
                            areaType: true,
                            data:rowData,
                            area:[wid,hei],
                            end: function () {
                                layuiFunciton.refresh('searchFrom', 'modelId',1);
                            }
                        });
                    }
                },
                del: {
                    returnData: function (rowData) {
                        layer.confirm('您确定要删除<span style="color: red">'+rowData.account+'</span>这条数据吗?', {
                            icon: 3,
                            title: '提示信息'
                        }, function (index) {
                            layuiFunciton.ajaxRequest({
                                url: '/ngu/sys/delete',
                                method: 'post',
                                data: {
                                    id: rowData.id
                                },
                                success: function (data) {
                                    console.log(data)
                                    if (data == 1) {
                                        layuiFunciton.success("操作成功！", function () {
                                            layer.close(index);
                                            layuiFunciton.refresh('searchFrom', 'modelId');
                                        });
                                    }

                                }
                            })
                        });
                    }
                }
            }
        });


    }
    //搜索
    this.find = function () {
        $("#search_btn").click(function () {
            layuiFunciton.refresh('searchFrom', 'modelId', 1);
        });
    }


    layui.use(['form'], function(){
        var form = layui.form
            ,layer = layui.layer
        //监听指定开关 禁用启用按钮
        form.on('switch(switchTest)', function(data){
            var  id =data.value.split("、")[0];
            var  enabled =data.value.split("、")[1];
            $.ajax({
                //监听指定开关方法
                url: '/ngu/sys/updateSysUser',
                type:'post',
                data: {
                    id:id,
                    enabled:enabled==1?0:1
                },
                success: function (data) {
                    if(data.data == 1){
                        layuiFunciton.success("操作成功！", function () {
                            layuiFunciton.refresh('searchFrom', 'modelId');
                        });
                    }

                }
            })

        });

    });

    //配置新增页面
    this.addNewHtml = function () {
        $("#addMenu_btn").click(function () {
            var wid = Math.floor($(window).width() / 7.5 * 5) + "px";
            var hei = Math.floor($(window).height() / 7.5 * 6) + "px";
            layuiFunciton.layerOpen({
                title: "新增人员信息",
                finder: '#addForm',
                content: "/ngu/pages/sys/user/add.html",
                areaType: true,
                area:[wid,hei],
                end: function () {
                    layuiFunciton.refresh('searchFrom', 'modelId',1);
                }
            });
        });
    }

}
$(function () {
    sysParam = new sysParam();
    sysParam.init(); //初始化
    sysParam.find(); //绑定事件
    sysParam.addNewHtml();//新增方法
})
